﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;
using DreamIn.Structures.Utils;
namespace DreamIn
{
	/// <summary>
	/// Interaction logic for LoginWindow.xaml
	/// </summary>
	public partial class LoginWindow : Window
	{
		public LoginWindow()
		{
			
			this.InitializeComponent();
            if (DreamIn.Properties.Settings.Default.checkbox_s)
            {
                checkbox1.IsChecked = true;
                usernamebox.Text = DreamIn.Properties.Settings.Default.username_s;
                passwordbox.Password = DreamIn.Properties.Settings.Default.password_s;
            }
            try
            {
                System.Net.IPHostEntry ip= System.Net.Dns.GetHostEntry("www.google.com");
               
            }
            catch
            {
             DreamIn.GUI.DreamWindow fereastra = new DreamIn.GUI.DreamWindow();
            fereastra.Show();
			Close();
                
               
            }
			
			// Insert code required on object creation below this point.
		
		}

		private void loginbutton_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			  if (checkbox1.IsChecked == true)
            {
                DreamIn.Properties.Settings.Default.checkbox_s = true;
                DreamIn.Properties.Settings.Default.username_s = usernamebox.Text;
                DreamIn.Properties.Settings.Default.password_s = passwordbox.Password;
                
            }
            else DreamIn.Properties.Settings.Default.checkbox_s = false;
            DreamIn.Properties.Settings.Default.Save();
			if (Account.Login(usernamebox.Text,passwordbox.Password))
			{
				DreamIn.GUI.DreamWindow mainwindow=new DreamIn.GUI.DreamWindow();
			mainwindow.Show();
			Close();
			}
			else {
				error_user.Text="Invalid Username or Password";
			}
		}

		private void offlinemodebt_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			DreamIn.GUI.DreamWindow fereastra = new DreamIn.GUI.DreamWindow();
            fereastra.Show();
			Close();
		}

		private void Register_bt_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			RegisterUser reguser=new RegisterUser();
		    reguser.Show();
		}
	}
}